<?php
namespace Admin\Model;
use Think\Model;
class LogisticsMessageModel extends Model {
	public $table='zjy_logistics_message';
	public $page; //当前页
	public $perpage; //每页显示
	public $message_id; //ID
	public $post; //提交的信息 数组
	public $ids; //IDs 主要用于删除
	public $sorts; //IDs 主要用于删除
	public $keyword; //关键词

	//获得列表 $page当前页 $perpage每页显示 当前默认用户名 姓名
	public function get_message_list()
	{
		$page=$this->page;
		$perpage=$this->perpage;
		//搜索
		$where='where b.member_state=1 and a.member_id=b.member_id ';
		//$where=' where 1 ';
		if($this->keyword){
			//$where.=" and (`member_email` LIKE '%".$this->keyword."%' )";
			$where.=" and (`load_area` LIKE '%".$this->keyword."%' or `unload_area` LIKE '%".$this->keyword."%' or `goods` LIKE '%".$this->keyword."%' or `weight` LIKE '%".$this->keyword."%' or `member_email` LIKE '%".$this->keyword."%' )";
		}
		/*
		if($this->pc_id){
			$pc_ids=$this->get_sub_pc_id($this->pc_id);
			$pc_ids=mb_strcut($pc_ids,1); //裁掉第一个，
			$where.="and c.pc_id in(".$pc_ids.")";
		}*/
		$start=($page-1)*$perpage;
		$Model=new Model();
		//$list=$Model->query("select a.* from ".$this->table." ".$where." order by member_reg_time desc limit $start,$perpage");
		$sql="SELECT a.*,b.member_id,b.member_email,b.member_mobile FROM ".$this->table." as a ,`zjy_member` as b ".$where." order by a.add_time desc limit $start,$perpage";
		//$sql="SELECT * FROM ".$this->table."  ".$where." order by add_time desc limit $start,$perpage";
		//echo $sql;exit;
		$list=$Model->query($sql);
		/*$Company=M('Company');
		//print_r($list);exit;
		foreach ($list as $k=>$v){
		$list[$k]['company_name']=$Company->where('member_id='.$v['member_id'])->getField('company_name');
		}*/
		//dump($list);exit;
		return $list;
	}

	//获得总数
	public function get_message_total()
	{
		//搜索
		$where='where b.member_state=1 and a.member_id=b.member_id ';
		//$where=' where 1 ';
		if($this->keyword){
			//$where.=" and (`content` LIKE '%".$this->keyword."%')";
			$where.=" and (`load_area` LIKE '%".$this->keyword."%' or `unload_area` LIKE '%".$this->keyword."%' or `goods` LIKE '%".$this->keyword."%' or `weight` LIKE '%".$this->keyword."%' or `member_email` LIKE '%".$this->keyword."%' )";
		}
		/*if($this->pc_id){
			$pc_ids=$this->get_sub_pc_id($this->pc_id);
			$pc_ids=mb_strcut($pc_ids,1); //裁掉第一个，
			$where.="and pc_id in(".$pc_ids.")";
		}*/
		$Model=new Model();
		$query=$Model->query("select count(a.message_id) as total from ".$this->table." as a, zjy_member as b ".$where." ");
		//$query=$Model->query("select count(message_id) as total from ".$this->table." ".$where." ");
		return $query[0]['total'];
	}

	//删除
	public function delete_message()
	{
		$ids=$this->ids;
		$Model=M("LogisticsMessage");
		foreach($ids as $v){
			$condition['message_id']=$v;
			if(!$Model->where($condition)->delete()){
				return false;
			}
		}
		return true;
	}

}